package com.guguskins.back.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guguskins.back.entity.GuFeedbackType;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuFeedbackTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-06-22
 */
@RestController
@RequestMapping("/feedbackType")
public class GuFeedbackTypeController {

    @Autowired
    private GuFeedbackTypeService feedbackTypeService;

    @GetMapping("/list")
    public ResultVo getList() {
        List<GuFeedbackType> feedbackTypeList = feedbackTypeService.list(new LambdaQueryWrapper<GuFeedbackType>() {
            {
                select(GuFeedbackType::getTypeId, GuFeedbackType::getTypeTitle);
                orderByAsc(GuFeedbackType::getTypeSort);
            }
        });
        return ResultVo.success(feedbackTypeList);
    }

    /**
     * 问题类型列表
     *
     * @return
     */
    @GetMapping("/back/list")
    public ResultVo selectList() {

        return ResultVo.success(feedbackTypeService.list());
    }

//    /**
//     * 问题类型修改
//     */
//    @PostMapping("/back/update")
//    public ResultVo updateFeedType(@RequestBody GuFeedbackType guFeedbackType) {
//        feedbackTypeService.updateById(guFeedbackType);
//        return ResultVo.success("修改成功");
//    }

    /**
     * 问题类型添加
     */
    @PostMapping("/back/insert")
    public ResultVo insertFeedType(@RequestBody  @Validated GuFeedbackType guFeedbackType) {
        feedbackTypeService.save(guFeedbackType);
        return ResultVo.success("添加成功");
    }

    @GetMapping("/back/remove")
   public ResultVo updateFeedType(@RequestParam(value = "id" ,required = false)Integer id) {
        feedbackTypeService.removeById(id);
       return ResultVo.success("删除");
    }
}

